import javax.swing.*;
import java.awt.*;

public class GameFrame extends JFrame {
    final int frameSize = 600;
    final int step = 30;
    public SnakeHead snakeHead = new SnakeHead(30,570,GameUtils.rightImg);
    public void launch(){
        System.out.println("33");
        this.setTitle("贪吃蛇");
        this.setSize(frameSize,frameSize);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        System.out.println("22");
        while (true){
            System.out.println("111");
            repaint();
            try {
                Thread.sleep(200);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }

    public void paint(Graphics graphics){
        System.out.println("55");
        graphics.setColor(Color.gray);
        graphics.fillRect( 0,0,frameSize,frameSize);
        graphics.setColor((Color.BLACK));

        int lineNum = frameSize / step;
        for(int i = 0; i < lineNum; i++){
            graphics.drawLine(0, i*step, frameSize, i*step);
            graphics.drawLine(i*step, 0, i*step, frameSize);
        }
        snakeHead.painSelf(graphics);
        System.out.println("44");
    }

    public static void main(String[] args) {
        GameFrame gameFrame =new GameFrame();
        gameFrame.launch();
    }
}
